package online.westonline.com.westonline.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 * 时间处理工具
 * Created by admin on 2018/5/17.
 */

public class TimeUtil {
    private TimeUtil()
    {

    }

    /**
     * 获取当前时间
     * @param time
     * @return
     */
    public static String getLocalTime(long time)
    {
        //转为中国时区的时间
        //利用calender获取时间
        SimpleDateFormat dateFormat = new SimpleDateFormat("MM月dd日 hh:mm",Locale.SIMPLIFIED_CHINESE);
        String mytime = dateFormat.format(time);
        //获取24小时制时间
        /*
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
        int min = Calendar.getInstance().get(Calendar.MINUTE);
        mytime = mytime+" "+(hour<10?"0"+hour:hour)+":"+(min<10?"0"+min:min);
        */
        return mytime;
    }

    /**
     * 获取精准时间
     * @param time
     * @return
     */
    public static String getLocalTimeNow(long time)
    {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss",Locale.SIMPLIFIED_CHINESE);
        return dateFormat.format(time);
    }
}
